<template>
	<view class="uni-tab-bar">
		<scroll-view scroll-x class="uni-swiper-tab" :style="scrollStyle">
			<block v-for="(tab,index) in tabBars" :key="tab.id">
				<view class="swiper-tab-list" :class="{'active':tabIndex==index}" @tap="tabtap(index)" :style="scrollItemStyle">
					{{tab.name}} {{tab.num?tab.num:''}}
					<view class="swiper-tab-line"></view>
				</view>
			</block>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		props: {
			tabBars: Array,
			tabIndex: Number,
			scrollStyle: {
				type: String,
				default: ""
			},
			scrollItemStyle: {
				type: String,
				default: ""
			}
		},
		methods: {
			// 切换列表
			tabtap(index) {
				this.$emit('tabtap', index);
			},
			// 获取指定列表
			async getList() {
				let currentIndex = this.tabIndex;
				// api   获取最新最热数据
				let url = ``;
				let [err, res] = await this.$http.get(url, {}, {
					token: true
				});
				let error = this.$http.errorCheck(err, res, () => {
					this.newslist[currentIndex].loadtext = "上拉加载更多";
				}, () => {
					this.newslist[currentIndex].loadtext = "上拉加载更多";
				});
				if (!error) return;
				let arr = [];
				let list = res.data.data.list;
				for (let i = 0; i < list.length; i++) {
					arr.push(this.__format(list[i]));
				}
				this.newslist[currentIndex].list = this.newslist[currentIndex].page > 1 ? this.newslist[currentIndex].list.concat(
					arr) : arr;
				this.newslist[currentIndex].firstload = true;
				if (list.length < 10) {
					this.newslist[currentIndex].loadtext = "没有更多数据了";
				} else {
					this.newslist[currentIndex].loadtext = "上拉加载更多";
				}
				return;
			},
		}
	}
</script>

<style lang="scss">
	.uni-swiper-tab {
		border-bottom: 1upx solid #EEEEEE;
		text-align: center;
	}

	.swiper-tab-list {
		color: #969696;
		font-weight: bold;
	}

	.uni-tab-bar .active {
		color: #343434;
	}

	.active .swiper-tab-line {
		border-bottom: 6upx solid $a1;
		width: 70upx;
		margin: auto;
		border-top: 6upx solid $a1;
		border-radius: 20upx;
	}
</style>
